package com.sgb.kjwl.viewmodel.enterprise;

import com.sgb.kjwl.api.APIManager;
import com.sgb.kjwl.api.EnterpriseAPIManager;
import com.sgb.kjwl.model.entity.ParentAreaEntity;
import com.sgb.kjwl.model.entity.enterprise.IpPickSelectEntity;
import com.sgb.kjwl.view.ui.activity.enterprise.ProfessionalTeamActivity;
import com.swgk.core.base.BaseViewModel;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.util.MToast;

import java.util.ArrayList;
import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class ProfessionalTeamActivityModel extends BaseViewModel {

    ProfessionalTeamActivity activity;
    private int pageNum = 1;
    IpPickSelectEntity entity1 = new IpPickSelectEntity("", "不限", "", "", "", "", "");


    public ProfessionalTeamActivityModel(ProfessionalTeamActivity activity) {
        this.activity = activity;
    }


    /**
     * 获取行业分类
     */
    public void getTradeCategry() {
        DialogHelper.showProgressDialog(activity, null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        EnterpriseAPIManager.getInstance().getEnterpriseAPI().getTradeCategry().enqueue(new Callback<BaseEntity<List<IpPickSelectEntity<List<IpPickSelectEntity>>>>>() {
            @Override
            public void onResponse(Call<BaseEntity<List<IpPickSelectEntity<List<IpPickSelectEntity>>>>> call, Response<BaseEntity<List<IpPickSelectEntity<List<IpPickSelectEntity>>>>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null || response.body().getData() == null) {
                    MToast.showToast(activity, "暂无数据");
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    List<IpPickSelectEntity<List<IpPickSelectEntity>>> list = new ArrayList<>();
                    list.addAll(response.body().getData());
//                    ParentAreaEntity entity = new ParentAreaEntity();
//                    entity.setNo("");
//                    entity.setName("不限");
//                    list.add(0, entity);
                    activity.showTabList(list);
                } else {
                    MToast.showToast(activity, response.body().getMsg());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<List<IpPickSelectEntity<List<IpPickSelectEntity>>>>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }
}
